import {useSelector} from "react-redux";
import {Link, Form} from "react-router-dom";


export default function ArticleEditButton({article}) {
    // 登录用户信息
    const currentUser = useSelector(state => state.user);
    const {author, favoriteCount, favorited, slug} = article;
    const isCurrentUser = author && currentUser && currentUser.username == author.username;
    // 自己查看
    if (isCurrentUser) {
        return (
            <>
                <Link to={`/article/${slug}/edit`} className="btn btn-sm btn-outline-secondary action-btn">
                    <i></i>编辑
                </Link>
                {" "}
                <Form method="delete" className="btn" action="delete">
                    <button className='btn btn-outline-danger btn-sm'>删除</button>
                </Form></>
        )
    }
// //     别人查看
    if (favorited) {
        return (
            // 取消喜欢
            <Form method="delete" className="btn">
                <button className="btn btn-sm  btn-outline-primary">
                    <i className="fa fa-heart-o"></i>{" "}{favoriteCount}
                </button>
            </Form>
        )
    } else {
        // 添加喜欢
        return (
            <Form method="post" className="btn">
                <button className="btn btn-sm  btn-outline-primary">
                    <i className="fa fa-heart-o"></i>{" "}{favoriteCount}
                </button>
            </Form>
        )
    }
}